package com.android.iridium;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;


public class MyWebView extends Activity {
	private  WebView webview;
	private String param = "";
	final Activity activity = this;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web);
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setAllowFileAccess(true);
        webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webview.getSettings().setSupportMultipleWindows(true);
       
        webview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);
 
                if(progress == 100)
                    activity.setTitle(R.string.app_name);
            }
            
           
            public boolean onCreateWindow(WebView view, boolean dialog,
            		            boolean userGesture,  android.os.Message resultMsg) {
            		   
//            		 	Intent myIntent = new Intent(getBaseContext(), GeocacherWebView.class);
//                    	myIntent.putExtra("param",   view.getUrl());
//                        startActivityForResult(myIntent, 0);
//                   
                        
                        WebView childView = new WebView(activity);
                        	
                                    childView.setWebChromeClient(this);
                        	
                                    WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
                        	
                                    transport.setWebView(childView);
                        	
                                    resultMsg.sendToTarget();
 
                        return true;
            }
            
            public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)  
            {  
                new AlertDialog.Builder(activity)  
                    .setTitle("javaScript dialog")  
                    .setMessage(message)  
                    .setPositiveButton(android.R.string.ok,  
                            new AlertDialog.OnClickListener()  
                            {  
                                public void onClick(DialogInterface dialog, int which)  
                                {  
                                    result.confirm();  
                                }  
                            })  
                    .setCancelable(false)  
                    .create()  
                    .show();  
          
                return true;  
            };  
            
            
        });
       // webview.getSettings().s
        Bundle extras = getIntent().getExtras();
        param = extras.getString("param");
    }
    
    
    public void onStart(){
    	super.onStart();
    		webview.loadUrl(param);

    	}
    
    
    public void home(View v){
    	super.finish();
    }
    public void back(View v){
    	finish();
    }
}